package cn.dankal.flyaudio.presenter;

import android.text.TextUtils;

import java.util.HashMap;
import java.util.Map;

import androidx.annotation.NonNull;
import api.ShopUserServiceFactory;
import cn.dankal.basiclib.pojo.BaseListResponse;
import cn.dankal.basiclib.pojo.BaseResponse;
import cn.dankal.basiclib.pojo.ProductEntity;
import cn.dankal.basiclib.pojo.req.AddShopCarReq;
import cn.dankal.basiclib.pojo.req.FavoritesShopReq;
import cn.dankal.basiclib.rx.AbstractSubscriber;
import cn.dankal.basiclib.util.ToastUtils;
import cn.dankal.flyaudio.contract.ClassificationContract;
import cn.dankal.flyaudio.contract.ProductDetailContract;
import cn.dankal.flyaudio.contract.StoreSearchContract;

public class ClassificationPresenter implements ClassificationContract.Presenter {

    private ClassificationContract.View mView;

    public static final String ORDER_BY_PRICE = "showPrice";

    public static final String ORDER_BY_EVALUATE = "goodCommentCount";

    public static final String ORDER_BY_SALES = "saleCount";

    private int page = 1;
    private int size = 10;


    @Override
    public void attachView(@NonNull ClassificationContract.View view) {
        mView = view;
    }

    @Override
    public void detachView() {
        mView = null;
    }

    @Override
    public void getShopListByCategoryAndSort(String categoryUuid, String orderBy, boolean asc, boolean isRefresh) {
        Map<String, Object> queryMap = new HashMap<>();
        queryMap.put("categoryUuid", categoryUuid);
        queryMap.put("asc", asc);
        if(!TextUtils.isEmpty(orderBy)){
            queryMap.put("orderBy", orderBy);
        }
        queryMap.put("page", page);
        queryMap.put("size", size);
        ShopUserServiceFactory.searchShop(queryMap)
                .subscribe(new AbstractSubscriber<BaseResponse<BaseListResponse<ProductEntity>>>(mView) {
                    @Override
                    public void onNext(BaseResponse<BaseListResponse<ProductEntity>> productEntityBaseResponse) {
                        mView.showProductList(productEntityBaseResponse.getData().getList(), isRefresh);
                    }
                });
    }
}
